home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / httpd / cgi-src / query.c < prev    next >
C/C++ Source or Header  |  1995-05-09  |  1KB  |  55 lines

  1.  
  2.  
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. typedef struct {
  8.     char name[128];
  9.     char val[128];
  10. } entry;
  11.  
  12. void getword(char *word, char *line, char stop);
  13. char x2c(char *what);
  14. void unescape_url(char *url);
  15. void plustospace(char *str);
  16.  
  17.  
  18.  
  19. main(int argc, char *argv[]) {
  20.     entry entries[10000];
  21.     register int x,m=0;
  22.     char *cl;
  23.  
  24.     printf("Content-type: text/html%c%c",10,10);
  25.  
  26.     if(strcmp(getenv("REQUEST_METHOD"),"GET")) {
  27.         printf("This script should be referenced with a METHOD of GET.\n");
  28.         printf("If you don't understand this, see this ");
  29.         printf("<A HREF=\"http://www.ncsa.uiuc.edu/SDG/Software/Mosaic/Docs/fill-out-forms/overview.html\">forms overview</A>.%c",10);
  30.         exit(1);
  31.     }
  32.  
  33.     cl = getenv("QUERY_STRING");
  34.     if(cl == NULL) {
  35.         printf("No query information to decode.\n");
  36.         exit(1);
  37.     }
  38.     for(x=0;cl[0] != '\0';x++) {
  39.         m=x;
  40.         getword(entries[x].val,cl,'&');
  41.         plustospace(entries[x].val);
  42.         unescape_url(entries[x].val);
  43.         getword(entries[x].name,entries[x].val,'=');
  44.     }
  45.  
  46.     printf("<H1>Query Results</H1>");
  47.     printf("You submitted the following name/value pairs:<p>%c",10);
  48.     printf("<ul>%c",10);
  49.  
  50.     for(x=0; x <= m; x++)
  51.         printf("<li> <code>%s = %s</code>%c",entries[x].name,
  52.                entries[x].val,10);
  53.     printf("</ul>%c",10);
  54. }
  55.